< previous page page_347 next page >

Page 347
This applies to ANSI strings where each character is one byte. What about Unicode strings where each character is two bytes? An array intended to hold a Unicode string might be defined as follows:
unsigned short UnicodeString[4];
Pointers
The C language is very big on pointers. The asterisk (*) character indicates a pointer. For example:
short *pIntVariable;
means that variable pIntVariable is a pointer to a short. Variable pIntVariable itself is 32 bits long. The data it points to is a short that is 16 bits long.
You've seen that an ANSI C language string is an array of char variables. But if you want to pass a string as a function parameter, you would not pass the entire array. Instead, you would pass a pointer to the string. What is a pointer to a string? It's a pointer that specifies the location of the first character in the array. The first character in the array is of type char, so a pointer to a string must be a pointer to a variable of type char. A pointer to a char variable is defined as follows:
char *pString;
What if you wanted to set the string pointer to the myString array defined earlier? A C programmer could do it like this:
pString = &myString[0];
The & operator means the address of the variable. In this case, it's exactly like the VarPtr operator a Visual Basic programmer would use to obtain the address of a VB variable.
References
A reference is a declaration that works just like a pointer, except it uses a different syntax. It uses the & character in a slightly different way. For example:
int myVariable;
int &ReferenceToVariable = myVariable;

 
< previous page page_347 next page >